<?php
/*
 * @FilePath: \crm\application\crm\controller\backlog\Ccc.php
 */
namespace app\crm\controller\backlog;

use app\crm\model\Client;
use app\crm\model\contract\Contract;
use app\crm\model\contract\DrawnUnder;
use app\crm\model\contract\Proceeds;
use think\Controller;


class Backlog extends Controller
{
    public function index()
    {
        return $this->fetch();
    }

    public function indextow()
    {
        return $this->fetch();
    }

    //第一个实例数据接口
    public function one()
    {
//  、
//        $aa = Client::alias('a')
//            ->join('Contract w','a.id=w.Client_id')
//            ->select();
//        dump($aa);
    }
    //第二个数据接口
    public function two()
    {
        //分页功能
        $page = $_GET['page'];
        $limit = $_GET['limit'];
        $aa = ($page-1)*$limit;
        $count = Proceeds::count();
        $index = Proceeds::select();
        echo json_encode(['code'=>0,'msg'=>'','count' =>$count,'data'=>$index]);
    }
    public function add()
    {
        $result = Contract::where('status',0)->column('number');
        $this->assign('number',$result);
        $result1 = Client::where('status','0')->column('name');
        $this->assign('name',$result1);
        return $this->fetch();
    }

    public function adds()
    {
        if($this->request->isPost()){
            $post = $this->request->post();
            $user = new DrawnUnder();
            if($user->allowField(true)->save($post)){
                return json('新增成功');
            } else {
                return json('添加失败');
            }
        }
    }
    //public
    public function table()
    {
        $page = $_GET['page'];
        $limit = $_GET['limit'];
        $aa = ($page-1)*$limit;
        $count = Proceeds::count();
        $index = DrawnUnder::select();
        echo json_encode(['code' => '0', 'msg' => '', 'count' => $count, 'data' => $index]);
    }

    public function del()
    {
        $id = $this->request->post();
        if (Contract::where('id', $id['id'])->delete()) {
            return json('删除成功');
        }
        return json('删除失败');
    }

    public function search()
    {
//        $number =  $_POST['number'];
        $id = $_POST['id'];
        $count = Contract::where('id', $id)->count();
        if ($result = Contract::whereLike('id', $id)->select()) {
            echo json_encode(['code' => 0, 'msg' => '成功', 'conut' => $count, 'data' => $result]);
        }

    }

}